package com.css.devops.rest;

import javax.annotation.Resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.css.devops.domain.BuildMonitor;
import com.css.devops.domain.PageResult;
import com.css.devops.domain.vo.BuildMonitorQueryCriteria;
import com.css.devops.service.DevopsBuildMonitor;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * Get Builder Job list
 */
@Api(tags = "Devops：构建Job的Pipeline接口")
@RestController
@RequestMapping("${devops-context}/buildMonitor")
public class DevopsBuildMonitorResource {

	@Resource(name = "${devops.service.build-monitor}")
	private DevopsBuildMonitor devopsBuildMonitor;
	
	@ApiOperation(value = "获取Devops构建job列表")
	@PostMapping("queryBuildMonitor")
	public ResponseEntity<PageResult<BuildMonitor>> queryBuildMonitor(@RequestBody BuildMonitorQueryCriteria buildMonitorQueryCriteria) {
		PageResult<BuildMonitor> pageResult = null;
		try {
			pageResult = devopsBuildMonitor.queryBuildMonitor(buildMonitorQueryCriteria);
		}catch (Exception e) {
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body(pageResult);
		}
		return ResponseEntity.ok(pageResult);
	}
	
}
